package com.example.boot1;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateDemo {
    //https://zhuanlan.zhihu.com/p/495693814?utm_id=0

    // 使用 DateTimeFormatter 线程安全类
    static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        LocalDateTime date = LocalDateTime.now();
        //日期转字符串
        String str = date.format(formatter);

        System.out.println("日期转换为字符串:"+str);

         DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDate date2 =LocalDate.parse(str,formatter2);
        System.out.println("日期类型:"+date2);


    }

}
